﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using System.Data;
using System.Data.SqlClient;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeProductByIDandPlidDataAction : BestLifeDataAction<DataTable>
    {
        string GvProductId;
        string GvPlId;
        DataTable GvPopTable = new DataTable();

        public BestLifeProductByIDandPlidDataAction(string Pproductid, string Pplid)
        {
            GvProductId=Pproductid;
            GvPlId = Pplid;
        }




        public override DataTable Body(SqlConnection PConn)
        {
            try
            {

                #region Datatable

                GvPopTable.Columns.Add("Pro_ID");
                GvPopTable.Columns.Add("Pl_Id");
                GvPopTable.Columns.Add("Brand_Name");
                GvPopTable.Columns.Add("Pro_Name");
                GvPopTable.Columns.Add("Pro_Price");
                GvPopTable.Columns.Add("Ret_Price");
                GvPopTable.Columns.Add("PV");
                GvPopTable.Columns.Add("BV");
                GvPopTable.Columns.Add("Quantity");


                #endregion

                List<string> LvList = new List<string>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetProductByProductidandPlidForPos";
                LvCommand.Parameters.Add(new SqlParameter("@Product_ID", GvProductId));//when passing parameters to the SP
                LvCommand.Parameters.Add(new SqlParameter("@Plid", GvPlId));//Pass Second Parameter

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {


                    GvPopTable.Rows.Add(GvPopTable.NewRow());

                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][6] = LvReader.GetValue(6).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][7] = LvReader.GetValue(6).ToString();
                    GvPopTable.Rows[GvPopTable.Rows.Count - 1][8] = "1";
                }
                return GvPopTable;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }












    }
}
